<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<html>
<head>
    <title>RequestBody传递JSON类型的参数</title>
    <script src="js/axios.js"></script>
    <script src="js/jquery.js"></script>
</head>
<body>
<button id="but1" onclick="sendAjax()">发送JSON数据到后端</button>

<script>
    function sendAjax() {
        let user = {id: 1, name: "哈哈哈",address:"北京", salary:132.4563, age: 18,ctime:"2021-12-23"};
        let userDate = JSON.stringify(user);
        // 使用ajax发送json数据到后端控制器
        $.ajax({
            url: "http://localhost:8080/ajax/t1.do",
            type: "post",
            contentType: "application/json",
            data: userDate,  // 发送的json类型参数
            success:function (res) {  //请求成功后的回调函数
               console.log(res)
            }
        });
    }






</script>
</body>
</html>
